<template>
	<!-- 全部订单的列表地址 -->
	<!-- 待付款 -->
	<!-- 待收货 -->
	<view>
		<!-- 地址 -->
		<view class="address-section">
			<view class="order-content">
				<text class="iconfont icon-dizhi"></text>
				<view class="cen">
					<view class="top">
						<text class="name">{{addressData.consignee}}</text>
						<text class="mobile">{{addressData.phone}}</text>
					</view>
					<text class="address">{{addressData.province}} {{addressData.city}} {{addressData.county}} {{addressData.address}} </text>
				</view>
				<text class="iconfont icon-arrow icon"></text>
			</view>
			<image class="a-bg" src="../../static/gwcymian/ddizi.png" style="width: 40rpx; height: 40rpx;"> </image>
		</view>

		<view class="goods-section">
			<!-- 商品列表 -->
			<view class="g-item" v-for="(item,index) in arr" :key='index'>
				<image :src='ouk==1 ? item.spuImg : item.img '>
				</image>
				<view class="right">
					<view class="title clamp">{{item.spuTitle}}</view>
					<view class="spec">{{item.title}}</view>
					<view class="price-box">
						<text class="price">￥{{item.originalPrice/100}}</text>
						<text class="number">￥{{item.price/100}}</text>
						<text class="number">*{{item.num}}</text>
					</view>
				</view>
			</view>
		</view>
		<!-- 金额明细 -->
		<view class="yt-list">
			<view class="yt-list-cell b-b">
				<text class="cell-tit ">商品金额</text>
				<text class="clamp">￥{{total}}</text>
			</view>
			<view class="yt-list-cell b-b">
				<text class="cell-tit ">折扣金额</text>
				<text class="cell-tip ">-￥{{paid}}</text>
			</view>
			<!-- <view class="yt-list-cell b-b" v-if="juan != 0">
				<text class="cell-tit ">优惠卷立减</text>
				<text class="cell-tip ">-￥{{juan/100}}</text>
			</view> -->
			<view class="yt-list-cell b-b">
				<text class="cell-tit ">运费</text>
				<text class="clamp">免运费</text>
			</view>
			<view class="yt-list-cell desc-cell">
				<text class="cell-tit clamp">备注</text>
				<input class="desc" type="text" v-model="desc" placeholder="请填写备注信息" placeholder-class="placeholder" />
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				desc: '', //备注
				couponList: [],
				addressData: {},
				sputitile: '请选择',
				arr: [],
				current: 0,
				order: '',
				gmtEnd: '',
				ouk: null,
			}
		},
		onLoad(option) {
			console.log(option)
			this.init()
			uni.request({
				url: 'http://192.168.1.54:8081/m.api?_gp=address&_mt=getDefAddress ',
				header: {
					'accesstoken': uni.getStorageSync('accessToken')
				},
				success: (res) => {
					this.addressData = res.data.data
				}
			})
			let that = this
			let id = JSON.parse(option.order)
			uni.request({
				url: 'http://192.168.1.54:8081/m.api?_gp=order&_mt=getOrderDetail&orderId=' + id,
				header: {
					'accesstoken': uni.getStorageSync('accessToken')
				},
				success: function(res) {
					that.arr = res.data.data.skuList
					console.log(that.arr,res,'；；；')
				}
			})
		},
		onShow() {
			if (uni.getStorageSync('accessToken') == '') {
				uni.showModal({
					title: '登录提示',
					content: '您尚未登录，是否立即登录',
					success: function(res) {
						if (res.confirm) {
							uni.navigateTo({
								url: '../login/login'
							})
						} else if (res.cancel) {
							// console.log('用户点击取消');
						}
					}
				});
			}
		},
		computed: {
			// 全额
			total() {
				let a = 0
				for (var i = 0; i < this.arr.length; i++) {
					a += this.arr[i].originalPrice * this.arr[i].num
				}
				return a / 100
			},
			// 折扣
			paid() {
				let a = 0
				for (var i = 0; i < this.arr.length; i++) {
					a += (this.arr[i].originalPrice - this.arr[i].price) * this.arr[i].num
				}
				return a / 100
			},
			// 实付
			shifu() {
				let a = 0
				for (var i = 0; i < this.arr.length; i++) {
					a += (this.arr[i].price * this.arr[i].num)
				}
				return a / 100
			},
		},
		methods: {
			init() {
				uni.request({
					url: 'http://192.168.1.54:8081/m.api?_gp=coupon&_mt=getUserCoupons ',
					method: 'GET',
					header: {
						'accesstoken': uni.getStorageSync('accessToken')
					},
					success: (res) => {
						this.couponList = res.data.data
						// console.log(res)
						for (var i = 0; i < res.data.data.length; i++) {//时间戳
							var date = new Date();
							date.setTime(res.data.data[i].gmtEnd);
							var month = date.getMonth() + 1;//月,为什么要加一呢因为跟中国的月份相差1所以有加1
							if (month < 10)
								month = "0" + month;
							var hours = date.getHours();//时
							if (hours < 10)
								hours = "0" + hours;
							var minutes = date.getMinutes();//钟
							if (minutes < 10)
								minutes = "0" + minutes;
											// 年									日
							var time = date.getFullYear() + "-" + month + "-" + date.getDate() + " " + hours + ":" + minutes;
							res.data.data[i].gmtEnd = time
							let that = this
						}
						// console.log(this.couponList)
					}
				})
			},
			swichNav(index) {
				this.current = index
				this.sputitile = this.couponList[this.current].title
				this.juan = this.couponList[this.current].discount
			},
		}
	}
</script>

<style scoped="scoped">
	.icon {
			width: 20rpx;
			height: 20rpx;
			margin: 37.5rpx;
			border-top: 2px solid #606266;
			border-right: 2px solid #606266;
			transform: rotate(45deg);
		}
	page {background: #f8f8f8;padding-bottom: 100upx;}
	.address-section {padding: 30rpx 0;background: #fff;position: relative;}
	.order-content {display: flex;align-items: center;}
	.icon-dizhi {flex-shrink: 0;display: flex;align-items: center;width: 90rpx;color: #888;font-size: 44rpx;justify-content: center;}
	.cen {display: flex;flex-direction: column;flex: 1;font-size: 28rpx;color: #303133;}
	.name {font-size: 34rpx;margin-right: 24rpx;}
	.address {margin-top: 16rpx;margin-right: 20rpx;color: #909399;padding-left: 30rpx;}
	.icon-you {font-size: 32rpx;color: #909399;margin-right: 30rpx;}
	.a-bg {position: absolute;left: 40rpx;bottom: 0;display: block;width: 100%;height: 5rpx; top: 55rpx;}
	.goods-section {margin-top: 16rpx;background: #fff;padding-bottom: 1px;}
	.g-header {display: flex;align-items: center;height: 84rpx;padding: 0 30rpx;position: relative;}
	.logo {display: block;width: 50rpx;height: 50rpx;border-radius: 100px;}
	.name {font-size: 30rpx;color: #606266;margin-left: 24rpx;}
	.g-item {display: flex;margin: 20rpx 30rpx;}
	.g-item image {flex-shrink: 0;display: block;width: 140rpx;height: 140rpx;border-radius: 4rpx;}
	.g-item .right {flex: 1;padding-left: 24upx;overflow: hidden;}
	.g-item .title {font-size: 30upx;color: #303133;margin-top: 10rpx;}
	.g-item .spec {font-size: 26rpx;color: #909399;padding: 10rpx 0;}
	.g-item .price-box {display: flex;align-items: center;font-size: 32rpx;color: #303133;padding-top: 10rpx;}
	.g-item .price-box .price {margin-bottom: 4rpx;font-size: 24rpx;text-decoration: line-through;}
	.g-item .price-box .number {font-size: 26rpx;color: #606266;margin-left: 20rpx;}
	.yt-list {margin-top: 16upx;background: #fff;}
	.yt-list-cell {display: flex;align-items: center;padding: 10rpx 30rpx 10rpx 40rpx;line-height: 70rpx;position: relative;}
	.yt-list-cell.cell-hover {background: #fafafa;}
	.yt-list-cell.b-b:after {left: 30rpx;}
	.cell-icon {height: 32rpx;width: 32rpx;font-size: 22rpx;color: #fff;text-align: center;line-height: 32rpx;background: #f85e52;border-radius: 4rpx;margin-right: 12rpx;}
	.cell-icon.hb {background: #ffaa0e;}
	.cell-icon.lpk {background: #3ab54a;}
	.cell-more {align-self: center;font-size: 24rpx;color: #909399;margin-left: 8rpx;margin-right: -10rpx;}
	.cell-tit {flex: 1;font-size: 26upx;color: #909399;margin-right: 10upx;}
	.cell-tip {font-size: 26rpx;color: #fa436a;}
	.cell-tip.disabled {color: #909399;}
	.cell-tip.red {color: #fa436a;}
	.yt-list-cell.desc-cell .cell-tit {max-width: 90rpx;}
	.yt-list-cell text {font-size: 24rpx;}
	.desc {flex: 1;font-size: 24rpx;color: #303133;}
	.footer {position: fixed; left: 0; bottom: 0; z-index: 995; display: flex; align-items: center; height: 90rpx; justify-content: space-between; font-size: 30rpx; background-color: #fff; color: #606266; box-shadow: 0 -1px 5px rgba(0, 0, 0, .1); z-index: 998; width: 100%;}
	.price-content {padding-left: 30rpx;}
	.price-tip {color: #fa436a;margin-left: 8rpx;}
	.footer .price {font-size: 36rpx;color: #fa436a;}
	.submit {display: flex; align-items: center; justify-content: center; width: 280rpx; height: 100%; color: #fff; font-size: 32rpx; background-color: #fa436a;}
	/* 优惠券面板 */
	.mask {display: flex; align-items: flex-end; position: fixed; left: 0; top: var(--window-top); bottom: 0; width: 100%; background: rgba(0, 0, 0, 0); z-index: 9995; transition: .3s;}
	.mask-content {width: 100%;min-height: 30vh;max-height: 70vh;background: #f3f3f3;transform: translateY(100%);transition: .3s;overflow-y: scroll;}
	.mask.none {display: none;}
	.mask.show {background: rgba(0, 0, 0, .4);}
	.mask.show .mask-content {transform: translateY(0);}

	/* 优惠券列表 */
	.coupon-item {display: flex;flex-direction: column;margin: 20rpx 24rpx;background: #fff;}
	.coupon-item .con {display: flex;align-items: center;position: relative;height: 120rpx;padding: 0 30rpx;}
	.coupon-item .con:after {position: absolute;left: 0;bottom: 0;content: '';width: 100%;height: 0;border-bottom: 1px dashed #f3f3f3;transform: scaleY(50%);}
	.coupon-item .left {display: flex;flex-direction: column;justify-content: center;flex: 1;overflow: hidden;height: 100rpx;}
	.coupon-item .title {font-size: 32rpx;color: #303133;margin-bottom: 10rpx;}
	.coupon-item .time {font-size: 24rpx;color: #909399;}
	.coupon-item .right {display: flex;flex-direction: column;justify-content: center;align-items: center;font-size: 26rpx;color: #606266;height: 100rpx;}
	.coupon-item .price {font-size: 44rpx;color: #fa436a;}
	.coupon-item .price:before {content: '￥';font-size: 34rpx;}
	.coupon-item .tips {font-size: 24rpx;color: #909399;line-height: 60rpx;padding-left: 30rpx;}
	.coupon-item .circle {position: absolute;left: -6rpx;bottom: -10rpx;z-index: 10;width: 20rpx;height: 20rpx;background: #f3f3f3;border-radius: 100px;}
</style>
